package com.bbu.javaexam.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bbu.javaexam.domain.MultiQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName MultiQuestionMapper.java
 * @Description TODO
 */
@Mapper
public interface MultiQuestionMapper extends BaseMapper<MultiQuestion> {
    /**
     * @throws
     * @title 查找填空题
     * @description
     * @author Alex
     */
    @Select("select * from multi_question where questionId in (select questionId from paper_manage where questionType = 1 and paperId = #{paperId})")
    List<MultiQuestion> findByIdAndType(Integer PaperId);

    /**
     * @throws
     * @title 通过分页查询填空题
     * @description
     * @author Alex
     */
    @Select("select * from multi_question")
    IPage<MultiQuestion> findAll(Page page);

    /**
     * @throws
     * @title 查找最后一条记录Id
     * @description
     * @author Alex
     */
    @Select("select questionId from multi_question order by questionId desc limit 1")
    MultiQuestion findOnlyQuestionId();

    /**
     * @throws
     * @title 新增一个选择题
     * @description
     * @author Alex
     */
    @Options(useGeneratedKeys = true, keyProperty = "questionId")
    @Insert("insert into multi_question(subject,question,answerA,answerB,answerC,answerD,rightAnswer,analysis,section,level) " +
            "values(#{subject},#{question},#{answerA},#{answerB},#{answerC},#{answerD},#{rightAnswer},#{analysis},#{section},#{level})")
    int add(MultiQuestion multiQuestion);

    /**
     * @throws
     * @title 通过试卷查找选择题
     * @description
     * @author Alex
     */
    @Select("select questionId from multi_question  where subject =#{subject} order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject, Integer pageNo);

}
